<template>
  <div v-if="store.auth.role=='管理员'">
    <el-input placeholder="学院" v-model="college" type="text" style="width: 140px"/>
    <el-button type="primary" @click="search">搜索</el-button>
  </div>
  <el-table :data="datas.slice((pageNum-1)*pageSize,pageNum*pageSize)" style="width: 100%" max-height="250" border>
    <el-table-column fixed label="序号" width="100">
      <template #default="scopes">
        {{ scopes.$index+1 }}
      </template>
    </el-table-column>
    <el-table-column fixed prop="college" label="学院" width="200" />
    <el-table-column prop="graduationGredit" label="绩点" width="200" />
    <el-table-column prop="englishTestFour" label="英语四级" width="200" />
    <el-table-column prop="computerLevel" label="计算机等级" width="200" />
    <el-table-column prop="totalCredit" label="总计学分" width="200" />
    <el-table-column prop="version" label="版本" width="200" />
  </el-table>
  <el-pagination
      background
      layout="sizes,prev,pager,next,jumper,->,total"
      :page-size.sync="pageSize"
      :current-page.sync="pageNum"
      :page-sizes="[5,8,10,15]"
      :total="totals"
      :hide-on-single-page="true"
      @current-change="getList"
      @size-change="getList1"
  />
</template>

<script setup>
import { get,post } from '@/utils/request.js'
import {ElMessage} from 'element-plus'
import { ref,onMounted } from 'vue'
import moment from 'moment';
import { reactive } from 'vue'
import {userStore} from '@/stores/counter.js'

const store=userStore()
const college=ref('')
const datas=ref([])
const totals=ref('')
const pageNum=ref(1)
const pageSize=ref(5)
const dialogVisible=ref(false)
const stu = reactive({
  college:'',
  graduationGredit:'',
  englishTestFour:'',
  computerLevel:'',
  totalCredit:'',
  version:''
})

const findAll=()=>get('/college/selectAllVersion',(message)=>{
    datas.value = message
    totals.value=message.length
},(message)=>{
  ElMessage.warning(message)
})

onMounted(()=>{
  findAll()
})

const search=()=>{
  if (college.value === '') college.value = "all"
  get('/college/selectByCollege/'+college.value,(message)=>{
    datas.value = []
    datas.value = message
    college.value=''
  },(message)=>{
    college.value=''
    ElMessage.warning(message)
  },(message)=>{
    college.value=''
    ElMessage.error(message)
  })
}

const getList=(pageNums)=>{
  pageNum.value=pageNums
}

const getList1=(pageSizes)=>{
  pageSize.value=pageSizes
}
</script>

<style scoped>
</style>